<?php
require_once("User.php");
require_once("FileName.php");
require_once("Util.php");

if($user->right["ReadDir"] == true)
{
	$path = simplify_filename('../data/'.$_POST['path']);
	if (string_begins_with($path, '../data') && $handle = opendir($path)) 
	{
		$arrayDir = array();
		$arrayFile = array();
		while (false !== ($file = readdir($handle))) 
		{
			if ($file != "." && $file != "..") 
			{
				if(is_dir($path.'/'.$file))
					$arrayDir[] = $file;
				else $arrayFile[] = $file;
			}
		}
		closedir($handle);
		echo json_encode(array("dir" => $arrayDir, "file" => $arrayFile));
	}
	else echo json_encode(array("error" => "Dir not allowed"));
}
else echo json_encode(array("error" => "No ReadDir right"));

?>